﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;

namespace JJYYCore.UIComponents.Slide
{
    public class SlideUIInRangeListener : MonoBehaviour
    {
        [SerializeField]
        private SlideUI slideUI;

        void Start()
        {
            if (!slideUI)
            {
                Debug.LogError("尝试启用滑动范围监听时，并未获取滑动范围监听模块!");
                return;
            }

            EventTrigger eventTrigger = gameObject.AddComponent<EventTrigger>();
            EventTrigger.Entry pointerEnterEntry = new EventTrigger.Entry
            {
                eventID = EventTriggerType.PointerEnter
            };

            pointerEnterEntry.callback.AddListener((data) => { OnPointerEnter((PointerEventData)data); });
            eventTrigger.triggers.Add(pointerEnterEntry);


            EventTrigger.Entry pointerExitEntry = new EventTrigger.Entry
            {
                eventID = EventTriggerType.PointerExit
            };
            pointerExitEntry.callback.AddListener((data) => { OnPointerExit((PointerEventData)data); });
            eventTrigger.triggers.Add(pointerExitEntry);
        }

        private void OnPointerEnter(PointerEventData data)
        {
            Debug.Log("POINT ENTER!");
            slideUI.IsMouseInArea = true;
        }

        private void OnPointerExit(PointerEventData data)
        {
            Debug.Log("POINT EXIT!");
            slideUI.IsMouseInArea = false;
        }
    }
}